package priv.lan.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import priv.lan.pojo.User;
import priv.lan.service.UserService;
import priv.lan.util.R;

import java.util.List;

/**
 * @Description: TODO
 * @author: lan
 * @date: 2021/12/1 15:17
 * @Version: 1.0
 */
@Api("UserController")
@RestController
public class UserController {

    @Autowired
    UserService userService;
    //实现登判断,并进行相应的跳转
    @ApiOperation(value = "hello",notes = "helloSwagger测试")
    @GetMapping("hello")
    public String hello1(){
        return "hello";
    }


    @GetMapping("list")
    public R test()
    {
        List<User> list = userService.list(null);
        return R.ok().data("items",list);
    }
    @PostMapping("addUser")
    public R addUser(@RequestBody User user){

        boolean isSave = userService.saveOrUpdate(user);
        if (isSave){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @PostMapping("login")
    public R login(@RequestBody User user){
        boolean islogin = userService.isLogin(user);
        if (islogin){

            return R.ok();
        }else {
            return R.error();
        }
    }

}
